package com.example.cshaoshao.testall.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.example.cshaoshao.testall.R;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

/**
 * Created by cshaoshao on 2017/8/30.
 */

public class VideoListAdapter extends BaseAdapter {
    public static final String TAG = "JieCaoVideoPlayer";
    Context context;
    String[] videoUrls;
    String[] videoTitles;
    String[] videoThumbs;

    public VideoListAdapter(Context context, String[] videoUrls, String[] videoTitles, String[] videoThumbs) {
        this.context=context;
        this.videoUrls=videoUrls;
        this.videoTitles=videoTitles;
        this.videoThumbs=videoThumbs;
    }

    @Override
    public int getCount() {
        return videoUrls.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null)
        {
            viewHolder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.activity_main,parent,false);
            convertView.setTag(viewHolder);
        }
        else
        {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.jcVideoPlayer= (JCVideoPlayerStandard) convertView.findViewById(R.id.videoplayer);
        viewHolder.jcVideoPlayer.setUp(videoUrls[position], JCVideoPlayer.SCREEN_LAYOUT_LIST,videoTitles[position]);
        return convertView;
    }
    class ViewHolder
    {
        JCVideoPlayerStandard jcVideoPlayer;
    }
}
